angular.module('mamApp').controller('coverManageController', ['$scope', '$state', '$uibModalInstance', 'FileUploader', 'params', 'ImageManager', function ($scope, $state, $uibModalInstance, FileUploader, params, ImageManager) {

    $scope.myImage="";
    $scope.imageString=""
    var reader = new FileReader();
    reader.onload = function (evt) {
        $scope.$apply(function ($scope) {
            $scope.myImage = evt.target.result;
        });
    };
    reader.readAsDataURL(params.image);
    console.log(params)


    var coverType=params.coverType;

    $scope.ok=function () {

        ImageManager.imageUpload({'base64':$scope.imageString,coverType:coverType,cpId:params.cpId}).then(function (result) {
            if(result.data.c=="s"){
                $uibModalInstance.close({url:result.data.fileVO.webUrl})
            }

        })

    }

    $scope.cancel=function () {
        $uibModalInstance.close({url:""})

    }
    
    
    
    

}])

